# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@io_bazel_rules_go//go:def.bzl", "go_library")

package(default_visibility = ["//src:__subpackages__"])

stamped_xdefs = {
    "buildNumber": "{STABLE_BUILD_NUMBER}",
    "buildSCMRevision": "{STABLE_BUILD_SCM_REVISION}",
    "buildSCMStatus": "{STABLE_BUILD_SCM_STATUS}",
    "buildSemver": "{STABLE_BUILD_TAG}",
    "buildTimeStamp": "{BUILD_TIMESTAMP}",
    "builtBy": "{STABLE_BUILT_BY}",
}

unstamped_xdefs = {
    "buildNumber": "0",
    "buildSCMRevision": "0000000",
    "buildSCMStatus": "Modified",
    "buildSemver": "0.0.0-dev",
    "buildTimeStamp": "0",
    "builtBy": "Unknown",
}

go_library(
    name = "goversion",
    srcs = ["version.go"],
    importpath = "px.dev/pixie/src/shared/goversion",
    x_defs = select({
        "//bazel:stamped": stamped_xdefs,
        "//conditions:default": unstamped_xdefs,
    }),
    deps = ["@com_github_blang_semver//:semver"],
)
